import { Container } from "./Container";
import { InvalidationType } from "../../../fl/core/InvalidationType";
import { GBoxDirection } from "globalVariable/GBoxDirection";
type int = number;
//class GBox
    
    export  class GBox extends Container
    {
       

        public /* override */ addChild(arg1: Object /* flash.display.DisplayObject */): Object /* flash.display.DisplayObject */
        {
            this._numChildChanged = true;
            return super.addChild(arg1);
        }

        public /* override */ addChildAt(arg1: Object /* flash.display.DisplayObject */, arg2: int): Object /* flash.display.DisplayObject */
        {
            this._numChildChanged = true;
            return super.addChildAt(arg1, arg2);
        }

        public /* override */ removeChild(arg1: Object /* flash.display.DisplayObject */): Object /* flash.display.DisplayObject */
        {
            this._numChildChanged = true;
            return super.removeChild(arg1);
        }

        public /* override */ removeChildAt(arg1: int): Object /* flash.display.DisplayObject */
        {
            this._numChildChanged = true;
            return super.removeChildAt(arg1);
        }

        public get direction(): string
        {
            return this._direction;
        }

        public set direction(arg1: string)
        {
            if (this._direction == arg1) 
            {
                return;
            }
            this._direction = arg1;
            invalidate(InvalidationType.ALL);
            return;
        }

        public get horizontalGap(): number
        {
            return this._horizontalGap;
        }

        public set horizontalGap(arg1: number)
        {
            if (this._horizontalGap == arg1) 
            {
                return;
            }
            this._horizontalGap = arg1;
            invalidate(InvalidationType.ALL);
            return;
        }

        public get verticalGap(): number
        {
            return this._verticalGap;
        }

        public set verticalGap(arg1: number)
        {
            if (this._verticalGap == arg1) 
            {
                return;
            }
            this._verticalGap = arg1;
            invalidate(InvalidationType.ALL);
            return;
        }

        public resetPosition2(): void
        {
            this.resetPosition();
            return;
        }

        protected resetPosition(): void
        {
            var loc1=0;
            var loc4=null;
            var loc2=0;
            var loc3=this.numChildren;
            if (this.direction != GBoxDirection.VERTICAL) 
            {
                if (this.direction == GBoxDirection.HORIZONTAL) 
                {
                    loc1 = 0;
                    while (loc1 < loc3) 
                    {
                        (loc4 = this.getChildAt(loc1)).x = loc2 + this.horizontalGap;
                        loc4.y = 0;
                        loc2 = loc4.x + loc4.width;
                        ++loc1;
                    }
                }
            }
            else 
            {
                loc1 = 0;
                while (loc1 < loc3) 
                {
                    (loc4 = this.getChildAt(loc1)).x = 0;
                    loc4.y = loc2 + this.verticalGap;
                    loc2 = loc4.y + loc4.height;
                    ++loc1;
                }
            }
            return;
        }

        protected /* override */ updateDisplayList(): void
        {
            if (this._numChildChanged || this.layChildChanged) 
            {
                this._numChildChanged = false;
                this.layChildChanged = false;
                this.resetPosition();
            }
            super.updateDisplayList();
            return;
        }

        public /* override */ get height(): number
        {
            var loc1=null;
            if (this.direction == GBoxDirection.HORIZONTAL) 
            {
                return super.height;
            }
            if (this.direction == GBoxDirection.VERTICAL) 
            {
                if (this.numChildren > 0) 
                {
                    loc1 = this.getChildAt((this.numChildren - 1));
                    return loc1.y + loc1.height;
                }
                return 0;
            }
            return super.height;
        }

        public /* override */ get width(): number
        {
            var loc1=null;
            if (this.direction == GBoxDirection.HORIZONTAL) 
            {
                if (this.numChildren > 0) 
                {
                    loc1 = this.getChildAt((this.numChildren - 1));
                    return loc1.x + loc1.width;
                }
                return 0;
            }
            if (this.direction == GBoxDirection.VERTICAL) 
            {
                return super.width;
            }
            return super.width;
        }

        public /* override */ dispose(arg1: Boolean=true): void
        {
            this._direction = GBoxDirection.HORIZONTAL;
            disposeChild(arg1);
            super.dispose(arg1);
            return;
        }

        public /* var */layChildChanged: Boolean=false;

        protected /* var */_numChildChanged: Boolean=false;

        private /* var */_direction: string="horizontal";

        private /* var */_horizontalGap: number=0;

        private /* var */_verticalGap: number=0;
    }
